package cn.com.cpic.insurance.rulecheck.util;

import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import cn.com.cpic.insurance.rulecheck.core.Context;

import com.google.common.collect.Maps;

public class ContextUtils {

	public static Context getContext(String json) throws JSONException {
		Context context = new Context();
		Map<String, Object> rtParam = Maps.newHashMap();

		JSONObject jo = new JSONObject(json);
		for (String name : JSONObject.getNames(jo)) {
			rtParam.put(name, jo.get(name));
		}

		context.setRtParam(rtParam);
		return context;
	}

	public static JSONObject toJSONObject(Map<String, Object> map) {
		return new JSONObject(map);
	}
}
